from django.core.management.base import BaseCommand
from rewards.models import RewardItem


SEED_ITEMS = [
    ('环保购物袋', 100, '帆布袋'),
    ('可重复使用水瓶', 150, '不锈钢保温水瓶'),
    ('植树证书', 200, '公益植树证书'),
]


class Command(BaseCommand):
    help = '初始化积分商城商品'

    def handle(self, *args, **options):
        created = 0
        for name, cost, desc in SEED_ITEMS:
            obj, is_created = RewardItem.objects.get_or_create(name=name, defaults={'points_cost': cost, 'description': desc, 'stock': 100})
            if is_created:
                created += 1
        self.stdout.write(self.style.SUCCESS(f'Initialized {created} RewardItem records'))